package com.free.common.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 返回结果对象
 *
 * @Author: hao.ding@insentek.com
 * @Date: 2021-07-23 10:49:44
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 5237123945274668730L;

    private T data;
    private Integer code;
    private String msg;

    public static <T> Result<T> succeed(String msg) {
        return of(null, 200, msg);
    }

    public static <T> Result<T> succeed(T model, String msg) {
        return of(model, 200, msg);
    }

    public static <T> Result<T> succeed(T model) {
        return of(model, 200, "");
    }

    public static <T> Result<T> of(T datas, Integer code, String msg) {
        return new Result<>(datas, code, msg);
    }

    public static <T> Result<T> failed(String msg) {
        return of(null, 500, msg);
    }

    public static <T> Result<T> failed(T model, String msg) {
        return of(model, 500, msg);
    }
}
